package com.junsi.util;

/**
 * 分页工具类
 * @author Administrator
 *
 */
public class PageUtil {

	
	//总行数
	private int rowCount;
	//每页显示条数
	private int pageSize = 1;
	//总页数
	private int pageCount;
	//当前页码
	private int pageNum = 1;
	//开始索引
	private int beginIndex;
	//结束索引
	private int endIndex;
	
	
	public PageUtil() {
		super();
	}

	


	public int getRowCount() {
		return rowCount;
	}

	public void setRowCount(int rowCount) {
		//数据集->总行数
		this.rowCount = rowCount;
		//总行数、每页显示条数 -> 总页数
		if(this.rowCount%this.pageSize == 0)
		{
			this.pageCount = this.rowCount/this.pageSize;
		}
		else
		{
			this.pageCount = this.rowCount/this.pageSize+1;
		}
		//当前页码
		this.pageNum = getPageNum();
		
		setPageNum(pageNum);
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
		
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
		//开始索引
		this.beginIndex = (this.pageNum - 1)*this.pageSize + 1;
		//结束索引
		this.endIndex = this.pageNum * this.pageSize;
		if(this.endIndex > this.rowCount)
		{
			this.endIndex = this.rowCount;
		}
	}

	public int getBeginIndex() {
		return beginIndex;
	}

	public void setBeginIndex(int beginIndex) {
		this.beginIndex = beginIndex;
	}

	public int getEndIndex() {
		return endIndex;
	}

	public void setEndIndex(int endIndex) {
		this.endIndex = endIndex;
	}

	@Override
	public String toString() {
		return "PageUtil [data="  + ", rowCount=" + rowCount + ", pageSize=" + pageSize + ", pageCount="
				+ pageCount + ", pageNum=" + pageNum + ", beginIndex=" + beginIndex + ", endIndex=" + endIndex + "]";
	}
	
}
